/*
 * 敵コントロール
 */
void
enemycontrol()
	{
	int	i,j;

	for ( i = 0 ; i < MAXENEMY ; i++ )
		{
		// 爆発中の処理
		if ( enemy[i].flag > 1 )
			{
			enemy[i].flag++;
			if ( enemy[i].flag > 9 )
				{
				enemy[i].flag = 0;
				if ( enemy[i].type == 99 )
					{
					skipflag = 0;
					PaletteFadeBlack(0,0,511);
					DspWait();
					DspWait();
					Wait(60);
					gamemain();
					}
				}
			}
		// 通常の処理
		else if ( enemy[i].flag == 1 )
			{
			if ( enemy[i].type == 99 )
				{
				bosscontrol(i);
				continue;
				}
			enemy[i].x += enemy[i].xspeed;

			if ( enemy[i].type == E_ROCK )
				{
				// 鉄球
				enemy[i].yspeed -= 4;
				enemy[i].y += enemy[i].yspeed;
				if ( enemy[i].y <= 0 ) enemy[i].yspeed = 20;
				}
			else if ( enemy[i].type == E_POLE )
				{
				// 柱
				if ( enemy[i].zspeed > 0 )
					{
					if ( enemy[i].z > FSZ - random(0x100) - 0x100 )
						{
						enemy[i].yspeed = 16;
						enemy[i].zspeed = -BASESPEED;
						}
					}
				if ( enemy[i].y > 0x60 ) enemy[i].yspeed = 0;
				enemy[i].y += enemy[i].yspeed;
				}
			else
				{
				// その他
				enemy[i].y += enemy[i].yspeed;
				}
			enemy[i].z += (enemy[i].zspeed - ship.zspeed);
			if ( enemy[i].x < 0 || enemy[i].x > FSX ) enemy[i].flag = 0;
			if ( enemy[i].y < -0x500 || enemy[i].y > FSY ) enemy[i].flag = 0;
			if ( enemy[i].z < -0x100 || enemy[i].z > FSZ ) enemy[i].flag = 0;

			// 敵弾発射
			if ( (enemy[i].type == E_ENGINE || enemy[i].type == E_RING )
				&& random(30) == 0 && enemy[i].z > 0x100 )
				{
				enemymslinit(i);
				}

			// 自弾との当たり判定
			for ( j = 0 ; j < MAXMSL ; j++ )
				{
				if ( msl[j].flag )
					{
					if ( mslhitcheck(i,j) )
						{
						enemy[i].hp--;
						if ( enemy[i].hp <= 0 )
							{
							PcmPlay(1,ADP_ZBAKU);
							enemy[i].flag = 2;
							oe[i].geometryTop = cube3;
							oe[i].geometryLength = sizeof(cube3) / sizeof(int);
							oe[i].material = NULL;
							ship.score += enemy[i].score;
							}
						else
							{
							PcmPlay(1,ADP_DAMAGE);
							}
						msl[j].flag = 0;
						}
					}
				}
			}
		}
	}
